package photorganizer.common.resource;

import java.util.ResourceBundle;

public class SimpleResourceManager implements ResourceManager {

	private final ResourceBundle bundle;

	public SimpleResourceManager(String baseName) {
		bundle = ResourceBundle.getBundle(baseName);
	}

	/* (non-Javadoc)
	 * @see photorganizer.common.resource.ResourceManager#get(java.lang.Object, java.lang.String)
	 */
	public String get(Object context, String name) {
		String prefix = getPrefix(context);
		return bundle.getString(prefix == null ? name : prefix + '.' + name);
	}

	protected String getPrefix(Object context) {
		if (context instanceof Class) {
			return ((Class<?>) context).getSimpleName();
		}
		if (context != null) {
			return getPrefix(context.getClass());
		}
		return null;
	}

}
